package cn.lyjuan.archetypes.bms.web.service;


import cn.lyjuan.archetypes.bms.web.cst.StateConst;
import cn.lyjuan.archetypes.bms.web.mapper.IWebActionGroupMapper;
import com.github.pagehelper.PageHelper;
import cn.lyjuan.archetypes.bms.common.entity.MgActionGroup;
import cn.lyjuan.archetypes.bms.common.mapper.MgActionGroupMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by ly on 2015/3/3.
 */
@Service("mgActionGroupService")
public class ActionGroupService
{
    @Autowired
    private MgActionGroupMapper actionGroupMapper;

    @Autowired
    private IWebActionGroupMapper webActionGroupMapper;

    /**
     * 后台搜索请求组信息
     *
     * @param param
     * @param pn
     * @param ps
     * @return
     */
    public List<MgActionGroup> queryGroups(Map<String, String> param, Integer pn, Integer ps)
    {
        PageHelper.startPage(pn, ps);
        List<MgActionGroup> list = webActionGroupMapper.selectGroups(param);

        return list;
    }

    /**
     * 所有分组
     * @return
     */
    public List<MgActionGroup> queryAllGropus()
    {
        List<MgActionGroup> list = webActionGroupMapper.selectGroups(null);

        return list;
    }

    /**
     * 根据组编号查询组信息
     *
     * @param groupid
     * @return
     */
    public MgActionGroup queryGroupById(Integer groupid)
    {
        return actionGroupMapper.selectByPrimaryKey(groupid);
    }


    /**
     * 添加组信息
     *
     * @param group
     */
    public void addGroup(MgActionGroup group)
    {
        group.setCreatetime(new Date());
        actionGroupMapper.insert(group);
    }

    /**
     * 更新组信息
     *
     * @param group
     */
    public void updateActionGroup(MgActionGroup group)
    {
        actionGroupMapper.updateByPrimaryKeySelective(group);
    }

    /**
     * 更新组信息
     *
     * @param groupid
     * @param status
     */
    public void updateStatus(Integer groupid, Boolean status)
    {
        webActionGroupMapper.updateGroupStatusById(groupid, status ? StateConst.OK : StateConst.NO);
    }

}
